package self.zhangkang.chart.view.kline

import self.zhangkang.chart.view.IndexInfoHelper
import self.zhangkang.chart.view.IndexNameConfig
import self.zhangkang.chart.view.kline.index.KLineBIAS
import self.zhangkang.chart.view.kline.index.KLineCCI
import self.zhangkang.chart.view.kline.index.KLineTurnOver
import self.zhangkang.chart.view.kline.index.KLineUnknown
import self.zhangkang.chart.view.kline.index.KLineViewKDJ
import self.zhangkang.chart.view.kline.index.KLineViewMACD
import self.zhangkang.chart.view.kline.index.KLineViewRSI
import self.zhangkang.chart.view.kline.index.KLineVolume
import self.zhangkang.chart.view.kline.index.KLineWR
import self.zhangkang.chart.view.kline.main.KLineBOLL
import self.zhangkang.chart.view.kline.main.KLineCYC
import self.zhangkang.chart.view.kline.main.KLineKLine
import self.zhangkang.chart.view.pool.PathPool
import self.zhangkang.chart.view.pool.RectPool

/**
 * @author : Android-张康
 * created on: 2023/5/10 21:42
 * description:
 */
internal class IndexInfoListHelper(
    private val pathPool: PathPool,
    private val rectPool: RectPool,
    private val kLineViewColor: KLineViewColor,
    private val kLineViewDimen: KLineViewDimen,
    private val indexNameConfig: IndexNameConfig
) : IndexInfoHelper<KLineIndex, KLineIndexInfo> {

    private val defaultList = emptyList<KLineIndex>()

    /**
     * 创建指标
     *
     * @param chartIndex 指标信息
     *
     * @return 返回创建好指标信息
     */
    override fun createKLineIndexInfo(chartIndex: KLineIndex): KLineIndexInfo {
        return when (chartIndex) {
            KLineIndex.UNKNOWN -> {
                KLineUnknown(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.KLine -> {
                KLineKLine(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.BOLL -> {
                KLineBOLL(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.CYC -> {
                KLineCYC(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.KDJ -> {
                KLineViewKDJ(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.MACD -> {
                KLineViewMACD(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.RSI -> {
                KLineViewRSI(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.TurnOver -> {
                KLineTurnOver(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.Volume -> {
                KLineVolume(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.CCI -> {
                KLineCCI(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.WR -> {
                KLineWR(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.BIAS -> {
                KLineBIAS(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }
        }
    }


    /**
     * 是否可以切换
     *
     * @param currentIndex 当前指标
     *
     * @return true 可以切换下一个，false 不可以切换下一个
     */
    override fun canSwitch(currentIndex: KLineIndexInfo): Boolean {
        return false
    }

    /**
     * 下一个指标
     *
     * @param currentIndex 当前指标
     *
     * @return 返回下一个指标信息
     */
    override fun nextIndex(currentIndex: KLineIndexInfo): KLineIndexInfo {
        var findIndex = -1
        defaultList.forEachIndexed { index, kLineIndex ->
            if (kLineIndex == currentIndex.getIndexInfo()) {
                findIndex = index
                return@forEachIndexed
            }
        }
        if (findIndex == -1) {
            return currentIndex
        }
        if (findIndex >= defaultList.size - 1) {
            return createKLineIndexInfo(defaultList[0])
        }
        return createKLineIndexInfo(defaultList[findIndex + 1])
    }

}